local function ptCount(tab)
	local i=0
	for _,_ in pairs(tab) do
		i=i+1
	end
	return i
end

function AT2_SanityCheck(validator,input) -- advanced modular sanity check
	if (type(validator)~="table" and type(input)~="table") then -- sanity check for sanity check, wow
		return false
	elseif (ptCount(validator)==0 and ptCount(input)==0) then
		return false
	else
		local sanity={}

		if (validator.xor==true) then
			sanity["xor"]=false
			for k,v in (input) do
				if (v==true) then 
					sanity["xor"]=true
				elseif (v==true and sanity["xor"]==true) then
					sanity["xor"]=false
					break
				end
			end
		end

		if (validator.min) then
			for _,v in pairs(input) do
				if (type(v)~="number") then 
					sanity["min"]=false
					break
				else
					if (v>=validator.min) then
						sanity["min"]=true
					else
						sanity["min"]=false
						break
					end
				end
			end
		end

		if (validator.max) then
			for _,v in pairs(input) do
				if (type(v)~="number") then 
					sanity["max"]=false
					break
				else
					if (v<=validator.max) then
						sanity["max"]=true
					else
						sanity["max"]=false
						break
					end
				end
			end
		end

		if (validator.all) then
			for _,v in pairs(input) do
				if (v==true) then
					sanity["all"]=true
				else
					sanity["all"]=false
					break
				end
			end
		end

		if (validator.nonemptystring) then
			for _,v in pairs(input) do
				if (type(v)~="string") then
					sanity["nonemptystring"]=false
					break
				else
					if (v=="") then
						sanity["nonemptystring"]=false
						break
					else
						sanity["nonemptystring"]=true
					end
				end
			end
		end

		if (validator.custom) then
			if (validator.custom(input)) then
				sanity["custom"]=true
			else
				sanity["custom"]=false
			end
		end

		local sane=true
		for _,v in pairs(sanity) do
			if (v~=true) then 
				sane=false
				break
			end
		end
		return sane
	end
end
